import os

import redis


class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY', 'default_secret_key')
    # SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:Zhaojianfei0820#@39.96.77.96:3306/th?charset=utf8mb4'
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:root@127.0.0.1:3306/th?charset=utf8mb4'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SESSION_TYPE = 'redis'
    SESSION_PERMANENT = False  # 设置 session 非永久
    SESSION_USE_SIGNER = True
    SESSION_KEY_PREFIX = 'flask-session:'  # Redis 中 session 的前缀
    SESSION_REDIS = redis.StrictRedis(host='localhost', port=6379, db=0)  # Redis 配置


class DevelopmentConfig(Config):
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = 'sqlite:///dev.db'


class TestingConfig(Config):
    TESTING = True
    SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db'


class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL', 'sqlite:///prod.db')


import random

tdengine_connection_params = {
    'username': 'root',
    'password': 'taosdata',
    'host': '127.0.0.1',
    'port': 6030,
    'database': 'archive'
}

mysql_connection_params = {
    'username': 'root',
    'password': 'root',
    'host': '127.0.0.1',
    'port': 3306,
    'database': 'th'
}

mssql_connection_params = {
    'username': 'sa',
    'password': 'Zhaojianfei0820#',
    'host': '127.0.0.1',
    'port': 1433,
    'database': 'SistarData',
    'driver': 'ODBC+Driver+17+for+SQL+Server'
}

redis_connection_params = {
    'host': 'localhost',  # Redis 服务器的地址
    'port': 6379,  # Redis 服务器的端口
    'db': 0,  # 使用的 Redis 数据库编号
    'max_connections': 30,  # 连接池的最大连接数
    'decode_responses': True
}

emqx_connection_params = {
    'broker': '127.0.0.1',
    'port': 1883,
    'client_id': f'python_mqtt_client_{random.randint(1, 10)}',
    'keep_alive_interval': 60,
    'password': None,
    'username': None,
    'topic_sub': None,
    'topic_pub': None
}

logger_params = {
    "logger_name": "opcua_adapter_logger",
    "total_level": 20,
    "file_handler_level": 10,
    "control_handler_level": 20,
    "file_name": r".\logs\opcua_adapter_logger.txt",
    "mode": "a",
    "max_bytes": 10485760,
    "backup_count": 10,
    "encoding": "UTF-8",
    "format": "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s"
}

opcua_adapter_params = {
    'alarm_consumer_queue_length': 100,
    'archive_consumer_queue_length': 100,
    'emqx_consumer_queue_length': 100,
    'acquisition_frequency': 1,  # 采集周期
    'monitor_frequency': 2,  # 监控周期
    'alarm_table_name': 'alarm',  # 报警的表格
    'archive_table_name': 'archive',  # 归档的数据库名称
    'emqx_worker': 1,
    'alarm_worker': 5,
    'archive_worker': 1
}
